#!/bin/bash

# self define var
GIT_DIR="/opt/k8s"
GIT_CODE="/opt/k8s/compile"
COMPOSER_FILE="/opt/k8s/compile/composer.json"
GIT_REPOSITORY="https://gitee.com/Edward527777633/compile.git"
TODAY_STR=`date +%Y%m%d%H%M%s`
IMAGE_NAME="php-nginx-compile"
IMAGE_REPO="szgcjc.com.cn:8080/service"


# judge dir
if [ -d ${GIT_CODE} ]; then
    rm -rf ${GIT_CODE}
fi

# in dir
cd ${GIT_DIR}
git clone ${GIT_REPOSITORY}


# cd composer install
if [ -f ${COMPOSER_FILE} ]; then 
    cd ${GIT_CODE}
    composer install -vvv
fi

# copy code into image
cd ${GIT_DIR}
docker build -t ${IMAGE_NAME}:${TODAY_STR} .

# image tag
docker tag ${IMAGE_NAME}:${TODAY_STR} ${IMAGE_REPO}/${IMAGE_NAME}:${TODAY_STR}

# push image
docker push ${IMAGE_REPO}/${IMAGE_NAME}:${TODAY_STR}

# select namespace 

# kubectl set deployment image
